package org.vincen.helloworld.jaxb;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class MapAdapter extends XmlAdapter<MapConverter, Map<String, String>> {

	@Override
	public Map<String, String> unmarshal(MapConverter v) throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		for(MapConverter.MapEntry me : v.getEntries()){
			map.put(me.getKey(), me.getValue());
		}
		return map;
	}

	@Override
	public MapConverter marshal(Map<String, String> v) throws Exception {
		MapConverter converter = new MapConverter();
		for(Map.Entry<String, String> entry : v.entrySet()){
			MapConverter.MapEntry me = new MapConverter.MapEntry(entry);
			converter.addEntry(me);
		}
		return converter;
	}
}
